package C048;

import java.util.Arrays;

/**
 * ClassName: C01
 * Package: C048
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/2/15 10:47
 * @Version 1.0
 * @Since 1.0
 */
public class C01 {
    public static void main(String[] args) {
        int[][] arr = {{1, 2, 3},
                {4, 5, 6},
                {7, 8, 9}};
        int[][] sumArr = getSumArr(arr);
        for (int i = 0; i < sumArr.length; i++) {
            System.out.println(Arrays.toString(sumArr[i]));
        }

    }

    private static int[][] getSumArr(int[][] arr) {
        int[][] res = new int[arr.length + 1][arr[0].length + 1];
        for (int i = 1; i < res.length; i++) {
            for (int j = 1; j < res[0].length; j++) {
                res[i][j] = res[i][j - 1] + res[i - 1][j] - res[i - 1][j - 1] + arr[i - 1][j - 1];
            }
        }
        return res;
    }


    public C01(int[][] matrix) {
        arr = matrix;
        sumArr = getSumArr(arr);
    }
    static int[][] arr = null;
    static int[][] sumArr = null;
    public static int sumRegion(int row1, int col1, int row2, int col2) {
        return sumArr[row2 + 1][col2 + 1] - sumArr[row2 + 1][col1] - sumArr[row1][col2 + 1] + sumArr[row1][col1];
    }
}
